#ifndef	__CXX_VIEWS_GRPH_FONT_H__
#define	__CXX_VIEWS_GRPH_FONT_H__

#include "grphbsc.h"
#include <string>

namespace visgrph
{

enum fontstyle
{
	fts_unknown = 0,
	fts_regular,
	fts_bold,
	fts_italic,
	fts_bold_italic,
};

enum font_charset
{
	fcs_unknown = -1,
	fcs_western,
	fcs_eastern,

	fcs_max,
	fcs_count = fcs_max,
};

enum dt_format
{
	dt_wordwrap = 1,
	dt_noclip = 2,
	dt_calcrect = 4,
	dt_left = 8,
	dt_center = 16,
	dt_right = 32,
	dt_top = 64,
	dt_middle = 128,
	dt_bottom = 256,
	dt_end_ellipsis = 512,
	dt_expend_tabs = 1024,
	dt_max = 1024,
};

std::string GRPH_EXPORT_API to_utf8(const char* str, const char* ot = "GB18030");
std::string GRPH_EXPORT_API to_utf8(const std::string& str, const char* ot = "GB18030");

class font_impl;
class fontinfo_impl;
class fcache_adaptor;

class GRPH_EXPORT_API fontinfo
{
public:
	fontinfo();
	~fontinfo();

public:
	const char* get_fontname(void);
	fontstyle get_fontstyle(void);

	// set as default font for specific language
	fontinfo* set_default(font_charset type);

	// get if this font is a default font for specific language
	// return fcs_unknown means this is not a defaut font
	font_charset get_default(void);

private:
	fontinfo(const fontinfo&);
	fontinfo& operator =(const fontinfo&);
};

// register a font
GRPH_EXPORT_API fontinfo* register_font(const char* fntname,
	const char* filename, unsigned int faceid,
	font_charset type = fcs_western,
	fontstyle ftype = fts_regular);

// font object
class GRPH_EXPORT_API font
{
public:
	font(char* fontname,
		unsigned int width,
		unsigned int height,
		fontstyle ftype = fts_regular,
		unsigned int faceid = 0);
	~font();

public:
	unsigned int get_fontsize(void) const;
	unsigned int width(void) const;
	unsigned int height(void) const;
	fontinfo* get_fontinfo(font_charset fchset) const;

	void char_spacing(float pix);
	bool line_spacing(float pix);
	bool line_scale(float ratio);

public:
	font_impl* _impl(void) const {
		return impl;
	}

private:
	font(const font&);
	font& operator=(const font&);

private:
	font_impl* impl;
};

enum formatted_text_flags
{
	ftf_clonetext = 1,
};

class formatted_text_impl;

class GRPH_EXPORT_API formatted_text
{
public:
	formatted_text();
	formatted_text(std::string content, bool bclone = true);
	formatted_text(const char* content, bool bclone = true);
	formatted_text(font& f, std::string content, bool bclone = true);
	formatted_text(font& f, const char* content, bool bclone = true);

	formatted_text(const formatted_text&);
	formatted_text& operator=(const formatted_text&);
	~formatted_text();

public:
	// set text
	const char* text(const char* txt, bool bclone = true);

	bool setfont(const font& f);
	bool setfont(fontinfo* finfo, int fwidth, int fheight);

	bool wordwrap(void);
	bool wordwrap(bool w);

	// set and get the wrapping rect
	int wrapping_width(void);
	int wrapping_width(int w);
	int wrapping_height(void);
	int wrapping_height(int h);
	bool wrapping_rect(int w, int h);
	bool get_wrapping_rect(int& w, int& h);

	// alignment
	bool left(void);
	bool center(void);
	bool middle(void);

public:
	formatted_text_impl* _impl(void) const {
		return impl;
	}

private:
	formatted_text_impl* impl;
};

class GRPH_EXPORT_API qtext : public formatted_text
{
public:
	qtext(const char* content)
		: formatted_text(content, false) {}
	qtext(std::string content)
		: formatted_text(content) {}
};

class GRPH_EXPORT_API qtext_gb18030 : public formatted_text
{
public:
	qtext_gb18030(const char* content)
		: formatted_text(to_utf8(content)) {}
	qtext_gb18030(std::string content)
		: formatted_text(to_utf8(content)) {}
};

};	// namespace visgrph

#endif	// __CXX_VIEWS_GRPH_FONT_H__
/* EOF */

